//
//  ZYCManageCourseRegistrationViewController.m
//  ZDSC
//
//  Created by ZDTX on 2021/7/18.
//

#import "ZYCManageCourseRegistrationViewController.h"
#import "ZYCElectiveLevelView.h"
#import "ZYCManageCourseSelectViewController.h"
#import "ZYCCourseStudentModel.h"
#import "ZYCElectiveSelectStudentView.h"
#import "ZYCProfileParentApplyViewController.h"
#import "ZYCProfileStudentManagementViewController.h"
#import "ZYCManagmentRecordParentViewController.h"

@interface ZYCManageCourseRegistrationViewController ()<ZYCElectiveLevelViewDelegate,ZYCElectiveSelectStudentViewDelegate>


@property (nonatomic, strong) ZYCElectiveLevelView *electiveLevelView;
@property (nonatomic, strong) ZYCElectiveSelectStudentView *electiveStudentView;
@end

@implementation ZYCManageCourseRegistrationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    NSInteger roleType =  [[NSUserDefaults standardUserDefaults] integerForKey:@"kUserRoleType"];
      if (roleType == 0) {//教师端
          self.title = @"选课报名";
          [self.view addSubview:self.electiveLevelView];
      }else{//家长端
          [self getAllStudent];
          self.title = @"选择学生";
          [self.view addSubview:self.electiveStudentView];
      }
}

// 获取所有学生
- (void)getAllStudent{
    [MrjSVProgressHUD showWithStatus:@"加载中..."];
    [[URLManager sharedURLManager] getUrlString:Appliance_Get_getMyStudents requestService:RequestServiceWorkBench parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
            
        } success:^(id  _Nullable responseObject) {
            if (SUCCESS(responseObject[@"code"])) {
                [MrjSVProgressHUD dismiss];
                NSArray *array = [NSArray yy_modelArrayWithClass:[ZYCCourseStudentModel class] json:responseObject[@"body"]];
                self.electiveStudentView.dataSource = array;
                [self.electiveStudentView reload];
            }
        } failure:^(NSError * _Nonnull error) {
            
        }];
}
- (ZYCElectiveLevelView *)electiveLevelView {
    if (!_electiveLevelView) {
        _electiveLevelView = [[ZYCElectiveLevelView alloc] initWithFrame:CGRectMake(0, kNavBarAndStatusBarHeight, kScreenWidth, kScreenHeight - kNavBarAndStatusBarHeight)];
        _electiveLevelView.delegate = self;
    }
    return _electiveLevelView;
}


- (ZYCElectiveSelectStudentView *)electiveStudentView {
    if (!_electiveStudentView) {
        _electiveStudentView = [[ZYCElectiveSelectStudentView alloc] initWithFrame:CGRectMake(0, kNavBarAndStatusBarHeight, kScreenWidth, kScreenHeight - kNavBarAndStatusBarHeight)];
        _electiveStudentView.delegate = self;
    }
    return _electiveStudentView;
}


#pragma mark - ZYCElectiveSelectStudentViewDelegate
// 选择学生
- (void)electiveSelectStudentViewDidClick:(ZYCCourseStudentModel *)model{
    
    if (self.enterType == ZYCCourseRegistrationEnterProfileCourseRegister) {
        ZYCProfileParentApplyViewController *vc = [ZYCProfileParentApplyViewController new];
        vc.studentId = model.s_id;
        [self.navigationController pushViewController:vc animated:YES];
    }else if(self.enterType == ZYCCourseRegistrationEnterApplianceCourseRegister){
        ZYCManageCourseSelectViewController *vc = [ZYCManageCourseSelectViewController new];
        vc.titleString = @"选课报名";
        vc.scope = model.scope;
        vc.studentId = model.s_id;
        vc.studentName = model.name;
        [self.navigationController pushViewController:vc animated:YES];
    }else if(self.enterType == ZYCCourseRegistrationEnterProfileStudentManagemt){
        ZYCProfileStudentManagementViewController *vc = [ZYCProfileStudentManagementViewController new];
        vc.studentId = model.s_id;
        [self.navigationController pushViewController:vc animated:YES];
    }else if(self.enterType == ZYCCourseRegistrationEnterApplianceStuAttendance){
        ZYCManagmentRecordParentViewController *vc = [[ZYCManagmentRecordParentViewController alloc] init];
        vc.model = model;
        [self.navigationController pushViewController:vc animated:YES];

    }
    
}
#pragma mark - ZYCElectiveLevelViewDelegate
- (void)electiveLevelViewDidClick:(ZYCElectiveLevelType)type{
    
    ZYCManageCourseSelectViewController *vc = [ZYCManageCourseSelectViewController new];
    if (type == ZYCElectiveLevelTypePrimary) {
        vc.scope = @"0";
        vc.titleString = @"小学部";
    }else{
        vc.scope = @"1";
        vc.titleString = @"中学部";
    }
    [self.navigationController pushViewController:vc animated:YES];
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
